<template>
	<view class="page_box">		
		<view class="content_box">
			<scroll-view scroll-y="true" @scrolltolower="loadMore" class="scroll-box">
				<checkbox-group @change="onSel" v-if="customerList.length">
					<view class="collect-list x-f" v-for="f in customerList" :key="f.id">
						<view class="y-start">
							<view class="goods-title more-t">{{ f.nickname }}</view>
							<view class="goods-title more-contact">{{ f.email }}</view>
							<view class="price">{{ f.mobile }}</view>
							
						</view>
						<view style="font-size:24rpx;width:220rpx;text-align:center;">
							<view style="color:#d19809">{{f.layer<0?1:f.layer}} 级分销</view>
							<view v-if="f.parent_name">推荐人:{{f.parent_name}}</view>
						</view>
					</view>
				</checkbox-group>
				<!-- 缺省页 -->
				<shopro-empty v-if="!customerList.length" :emptyData="emptyData"></shopro-empty>
				<!-- 更多 -->
				<!-- <view v-if="customerList.length" class="cu-load text-gray" :class="loadStatus"></view> -->
			</scroll-view>
		</view>		
		<!-- 自定义底部导航 -->
		<!-- <shopro-tabbar></shopro-tabbar> -->
		<!-- 关注弹窗 -->
		<!-- <shopro-float-btn></shopro-float-btn> -->
		<!-- 连续弹窗提醒 -->
		<!-- <shopro-notice-modal></shopro-notice-modal> -->
		<!-- 登录提示 -->
		<!-- <shopro-login-modal></shopro-login-modal> -->
	</view>
</template>

<script>
import shoproMiniCard from '@/components/shopro-mini-card/shopro-mini-card.vue';
import shoproEmpty from '@/components/shopro-empty/shopro-empty.vue';
export default {
	components: {
		shoproMiniCard,
		shoproEmpty
	},
	data() {
		return {
			isSel: false,
			allSel: false,
			routerTo: this.$Router,
			selList: [],
			emptyData: {
				img: '/static/imgs/empty/empty_goods.png',
				tip: '暂无分销客户'
			},
			customerList: [],
			total: 0,
			loadStatus: '', //loading,over
			currentPage: 1,
			lastPage: 1,
			showShare:false,
			showShareUrl:"",
		};
	},
	computed: {},
	onShow() {
		this.init();
	},
	onHide() {
		this.dealerList = [];
	},
	methods: {
		// init
		init() {
			return Promise.all([this.GetDistributeUsers()]);
		},
		onSel(e) {
			let items = this.dealerList,
				values = e.detail.value;
			this.selList = values;
			items.forEach(i => {
				if (values.includes(i.goods_id.toString())) {
					this.$set(i, 'checked', true);
				} else {
					this.$set(i, 'checked', false);
				}
			});
			if (this.selList.length < items.length) {
				this.allSel = false;
			} else {
				this.allSel = true;
			}
		},
		onSet() {
			this.isSel = !this.isSel;
		},
		onAllSel() {
			this.allSel = !this.allSel;
			this.selList = [];
			const { dealerList } = this;
			dealerList.forEach(i => {
				if (this.allSel) {
					this.$set(i, 'checked', true);
					this.selList.push(i.goods_id);
				} else {
					this.$set(i, 'checked', false);
				}
			});
		},
		// 加载更多
		loadMore() {
			if (this.currentPage < this.lastPage) {
				this.currentPage += 1;
				this.GetDistributeUsers();
			}
		},
		// 收藏列表
		GetDistributeUsers() {
			let that = this;
			let userInfo=JSON.parse(uni.getStorageSync("userInfo"));
			
			uni.request({
			    url: this.$config.API_URL+"Distribute/GetDistributeUsers",
				method:"POST",
				data:{
					"uid":userInfo.StoreUserInfo.Uid
				},
				success: (result) => {					
					that.customerList = result.data;
					
				},
			})
		},
		// 路由跳转
		jump(path, parmas) {
			this.$Router.push({
				path: path,
				query: parmas
			});
		},
		share(f){
			this.showShare=true;
			let url='/pages/app/dealer/index';
			this.showShareUrl=window.location.href.replace("/pages/app/dealer/myCustomer",url)+"?title="+f.pagetitle+"&name="+f.buttonname+"&code="+f.code;
		},
		onCopy() {
			let that = this;
			uni.setClipboardData({
				data: this.showShareUrl,
				success: function(data) {
					//#ifdef H5
					that.$tools.toast('已复制到剪切板');
					//#endif
				},
				fail: function(err) {},
				complete: function(res) {}
			});
		},
	}
};
</script>

<style lang="scss">
// @import url('//at.alicdn.com/t/font_956911_py2eooakww9.css');
.head_box {
	height: 70rpx;
	padding: 0 30rpx;

	.count-box {
		font-size: 26rpx;
		color: #999;

		.all-num {
			color: #a8700d;
		}
	}

	.set-btn {
		background: none;
		font-size: 26rpx;
		color: #a8700d;
	}
}

.collect-list {
	padding: 30rpx 20rpx;
	background: #fff;
	margin-bottom: 20rpx;

	.goods-radio {
		transform: scale(0.7);
		margin-right: 20rpx;
	}
	
	.y-start{
		display:flex;
		flex-direction:row;
		flex-wrap:wrap;
		width:100%;
		
		.goods-title{
			display:inline-block;
			width:60%;
			font-size:16px;
			flex-grow:1;
			flex-shrink:1;
		}
		.sub-tip{
			display:inline-block;
			font-size:14px;
			flex-grow:0;
			flex-shrink:0;
			
		}
		.price{
			display:block;
			margin-top:5px;
			font-size:24rpx;
			color:#888888;
			width:100%;
		}
		.more-contact{
			margin-top:5px;
			font-size:24rpx;
			color:#888888;
			
		}
		.button{
			text-align:right;
			margin-top:20rpx;
			
			text{
				display:inline-block;
				margin-right:20rpx;
				font-size:28rpx;
				
				&:before{
					font-size:32rpx;
					margin-right:10rpx;
				}
			}
		}
	}
}

.tools-box {
	height: 100rpx;
	width: 750rpx;
	padding: 0 20rpx;
	background: #fff;

	.check-all {
		font-size: 26rpx;

		.check-all-radio {
			transform: scale(0.7);
		}
	}

	.close-btn {
		width: 200rpx;
		height: 70rpx;
		background: linear-gradient(90deg, rgba(233, 180, 97, 1), rgba(238, 204, 137, 1));
		box-shadow: 0px 7rpx 6rpx 0px rgba(229, 138, 0, 0.22);
		border-radius: 35rpx;
		padding: 0;
		color: rgba(#fff, 0.9);
	}
}

.shareProp{
	position:fixed;
	top:0px;
	bottom:0px;
	left:0px;
	right:0px;
	display:flex;
	align-items:center;
	justify-content:center;
	
	.sharePropBox{
		display:inline-block;
		width:80%;
		// height:200rpx;
		
		padding:30rpx;
		line-height:40rpx;
		font-size:28rpx;
		
		background-color:white;
		border:solid 1px #cccccc;
		
		.shareContent{
			margin-top:10rpx;
			 display:flex;
			 justify-content:space-between;
			.item:nth-of-type(1){
				height:50rpx;
				line-height:50rpx;
				width:80rpx;
				flex-grow:0;
				flex-shrink:0;
				font-size:28rpx;
				
				text-align:left;
				// background-color:#cccccc;
			}
			.item:nth-of-type(2){
				height:50rpx;
				line-height:50rpx;
				flex-grow:1;
				font-size:28rpx;
				background-color:#efefef;
			}
			.item:nth-of-type(3){
				height:50rpx;
				line-height:50rpx;
				width:80rpx;
				flex-grow:0;
				flex-shrink:0;
				font-size:28rpx;
				text-align:center;
				background-color:#cccccc;
			}
			.item:nth-of-type(4){
				
			}
			
		}
	}
}

</style>
